package com.lvmama.service.impl;

import com.lvmama.base.ResultBase;
import com.lvmama.entity.User;
import com.lvmama.enums.ErrorCodeEnum;
import com.lvmama.service.UserService;
import com.lvmama.system.dao.UserDao;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    UserDao userDao;

    @Override
    public ResultBase<User> findByUsername(String username) {

        log.info("findByUsername start. username:{}", username);

        ResultBase<User> result = new ResultBase<>();
        try{
            User user = userDao.findByUsername(username);
            if (null != user) {
                result.setSuccess(true);
                result.setValue(user);
            }
        }catch (Exception e){
            result.setErrorCode(ErrorCodeEnum.UNKOWN_ERROR.getCode());
            result.setErrorMsg(ErrorCodeEnum.UNKOWN_ERROR.getMsg());
            log.error("findByUsername error:{}", e.getMessage(), e);
        }

        return result;
    }
}
